<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content") != null ? request.getParameter("content") : "";
%>
<html>
<head>
    <title>企业网站管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor/plugins/code/prettify.js"></script>

    <style>
        form{
            margin-left: 10px;
        }
        .form-group{
            margin-top: 20px
        }
        .form-group input{
            height: 30px;
        }
    </style>
    <script>
        KindEditor.ready(function(K) {
            var editor1 = K.create('textarea[name="content"]', {
                cssPath : '../plugins/code/prettify.css',
                allowFileManager : true,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                }
            });
            prettyPrint();
        });
    </script>
    <script>
        function getMinlist() {
            var max_id=$('#maxid').val();
            $('#minid').html('<option value="">----请选择下拉菜单----</option>');
            $.ajax({
                url : "${pageContext.request.contextPath}/getMinList/"+max_id,
                type : "GET",
                dataType : "json",
                success : function(data){
                    if(data!=null){
                        $(data).each(function(index){
                            $("#minid").append(
                                '<option value="'+data[index].min_id+'">'+data[index].min_name+'</option>'
                            );
                        });
                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="panel admin-panel">
    <form class="form-x" action="${pageContext.request.contextPath}/addInfo" method="post">
        <div class="form-group">
            <div class="label">
                <%--@declare id="sitename"--%>
                    <label for="sitename">标题：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" name="title" size="50" placeholder="请输入标题" data-validate="required:请输入标题" autofocus/>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label for="sitename">作者：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" name="author" size="50" placeholder="请输入作者" data-validate="required:请输入作者,length#>=1:新密码不能小于1位" autofocus/>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label for="sitename">发布日期：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" name="adddate" size="50" placeholder="请输入日期" data-validate="required:请输入日期" autofocus/>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label for="sitename">内容：</label>
            </div>
            <div class="field">
                <textarea name="content" class="input" style="height:450px; border:1px solid #ddd;"></textarea>
                <%=htmlspecialchars(htmlData) %>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            导航菜单：
            <select name="maxid" id="maxid" onclick="getMinlist()">
                <option value="">请选择导航菜单</option>
                <c:forEach items="${requestScope.listMaxMenu}" var="a">
                    <option value="${a.max_id}">${a.max_name}</option>
                </c:forEach>
            </select>
            下拉菜单：
            <select name="minid" id="minid">
                <option value="">----请选择下拉菜单----</option>
            </select>
        </div>
        <div class="form-group">
            <div class="label">
                <label></label>
            </div>
            <div class="field">
                <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
            </div>
        </div>
    </form>
</div>
</body>
</html>
<%!
    private String htmlspecialchars(String str) {
        str = str.replaceAll("&", "&amp;");
        str = str.replaceAll("<", "&lt;");
        str = str.replaceAll(">", "&gt;");
        str = str.replaceAll("\"", "&quot;");
        return str;
    }
%>